//by qyzyq
#include <bits/stdc++.h>

using namespace std;

bool judge(string st)
{
	int num = 0, add = 0;
	for (int i = 0; i < st.size(); i++)
	{
		if (isdigit(st[i]))
		{
			if (st[i] == '0' && !num) 
				return 0;
			num = num * 10 + (st[i] - 48);
		}
		else
		{
			if (!isdigit (st[i - 1]))
				return 0;
			++ add;
			if (add <= 3) 
				if (st[i] != '.')
					return 0;
			if (add > 3)
				if (st[i] != ':')
					return 0;
			if (num > 255) return 0;
			num = 0;
		}
	}
	if (add != 4) return 0;
	if (num > 65535) return 0;
	return 1;
}

map<string, int> mp;

int main()
{
	freopen("network.in", "r", stdin);
	freopen("network.out", "w", stdout);
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		string st1, st2;
		cin >> st1 >> st2;
		if (!judge (st2))
			puts ("ERR");
		else
			if (st1 == "Server")
				if (mp[st2]) puts ("FAIL");
				else mp[st2] = i, puts("OK");
			else
				if (mp[st2]) printf("%d\n", mp[st2]);
				else puts ("FAIL");
	}
	return 0;
}
